function [U0,V0,s,Up,Vp,Vpi]=IncrementalSVD(c,s,U0,Up,V0,Vp,Vpi,trunc)
%removal fringe of photo using method of Matthew Brand,his paper is
%Incremental singular value decomposition of uncertain data with missing
%values,
%Web:https://link.springer.com/chapter/10.1007%2F3-540-47969-4_47?LI=true

% refimages=refimages(:);
% % bgRegion=find(bgmask(:)==1);
% trunc=0;
% c=refimages(bgmask(:)==1);
% s=norm(c);
% U0=c/s;
% V0=1;
% Up=1;
% Vp=1;
% Vpi=1;
% while (true)
    r=length(s);
    U=U0*Up;
    V=V0*Vp;
%     c=U*s*V;
%     if isempty(c)
%         continue;
%     end
    I=eye(r);
    l=(U')*c;
    j=c-U*l;
    k=norm(j,'fro');
    j=j/k;
    disp(['k=' num2str(k)]);
    if k<trunc
        k=0;
    end
    Q=InsertMat(Diagonalization(s),k,l,0);
    Q=deleteRowCol(Q);
    [A,s,B]=svd(Q);
    s=deleteRowCol(s);
%     B=B.';


    if k<trunc
        Up=Up*A(1:r,1:r);
        W=B(1:r,1:r);
        w=B(r+1,1:r);
        Wi=(I+w'*w/(1-w*w'))*W';
%         Wi=W'+(w'/(1-w*w'))*(w*W');
        Vp=Vp*W;
        Vpi=Wi*Vpi;
        V0=[V0;w*Vpi];
    else
        Up=InsertMat(Up,1,0,0)*A;
        U0=[U0 j];
        V0=InsertMat(V0,1,0,0);
        Vp=InsertMat(Vp,1,0,0)*B;
        Vpi=(B')*InsertMat(Vpi,1,0,0);
    end
% end


